import { defineComponent, ref } from 'vue'
import { NCard, NDescriptions, NDescriptionsItem, useMessage } from 'naive-ui'
import { getScheduleInfo } from '@/service/modules/integration-assets'
import { useRouter } from 'vue-router'

const infoSchedule = defineComponent({
  name: 'infoSchedule',
  setup() {
    const scheduleData = ref({
      name: '',
      taskParams: '',
      submitTime: '',
      startTime: '',
      endTime: '',
      tableName: '',
      failRetryTimes: 0,
      failRetryInterval: 0,
      timeoutFlag: 0,
      timeoutNotifyStrategy: 0,
      timeout: 0,
      delayTime: 0,
      userName: 0,
      sql: ''
    })

    const router = useRouter()

    const getInfo = function () {
      // @ts-ignore
      getScheduleInfo(router.currentRoute.value.query.tableName)
        .then((res: any) => {
          scheduleData.value = res.data
        })
        .catch((err: any) => {
          message.error(err.msg ? err.msg : '接口未知错误')
        })
    }

    getInfo()

    const message = useMessage()

    return {
      scheduleData,
      router,
      getInfo,
      message
    }
  },
  render() {
    return (
      <NCard>
        <NDescriptions title={'任务信息'}>
          <NDescriptionsItem label='工作流名称'>
            {this.scheduleData.name}
          </NDescriptionsItem>
          <NDescriptionsItem label='表名名称'>
            {this.scheduleData.name}
          </NDescriptionsItem>
          <NDescriptionsItem label='失败重试次数'>
            {this.scheduleData.failRetryTimes}
          </NDescriptionsItem>
          <NDescriptionsItem label='失败重试间隔'>
            {this.scheduleData.failRetryInterval}
          </NDescriptionsItem>
          <NDescriptionsItem label='延时执行时间'>
            {this.scheduleData.delayTime}
          </NDescriptionsItem>
          <NDescriptionsItem label='执行用户'>
            {this.scheduleData.userName}
          </NDescriptionsItem>
          <NDescriptionsItem label='超时标志'>
            {this.scheduleData.timeoutFlag}
          </NDescriptionsItem>
          <NDescriptionsItem label='超时通知策略'>
            {this.scheduleData.timeoutNotifyStrategy}
          </NDescriptionsItem>
          <NDescriptionsItem label='超时时长'>
            {this.scheduleData.timeout}
          </NDescriptionsItem>
          <NDescriptionsItem label='任务提交时间'>
            {this.scheduleData.submitTime}
          </NDescriptionsItem>
          <NDescriptionsItem label='预期完成时间'>
            {this.scheduleData.startTime}
          </NDescriptionsItem>
          <NDescriptionsItem label='结束时间'>
            {this.scheduleData.endTime}
          </NDescriptionsItem>
          <NDescriptionsItem label='任务详情'>
            {this.scheduleData.sql}
          </NDescriptionsItem>
        </NDescriptions>
      </NCard>
    )
  }
})

export default infoSchedule
